package org.noote.libs.spidy.comm;

public class IPCommandProtocol {

	protected static final int _PROTOCOL_VERSION_MAJOR=0;
	protected static final int _PROTOCOL_VERSION_MINOR=5;
	public static final String getProtocolVersion()
	{
		return Integer.toString(_PROTOCOL_VERSION_MAJOR)+"."+Integer.toString(_PROTOCOL_VERSION_MINOR);
	}

	//////////////////////////////////
	///
	/// Client class for IP communication
	///
	/////////////////////////////////
	static final String CMD_START_TRAME = "#";
	static final String CMD_END_TRAME = "$";
	protected static String _bounding(String sCmd, String sOp, String sParams)
	{
		return CMD_START_TRAME+sCmd+((sOp.length()>0)?"_"+sOp:"")+":"+sParams+CMD_END_TRAME+"\n";
	}

	/////////////////////////////////
	// Connect
	static final String CMD_CONNECT = "c";
	public static String sendAskConnection()
	{
		return _bounding(CMD_CONNECT, "", "");
	}
	
	/////////////////////////////////
	// Alive
	static final String CMD_ALIVE = "a";
	public static String sendAlive()
	{
		return _bounding(CMD_ALIVE, "", "");
	}
	
	/////////////////////////////////
	// Version
	static final String CMD_QUIT = "quit";
	public static String sendQuit()
	{
		return _bounding(CMD_QUIT, "", "");
	}

	/////////////////////////////////
	// Version
	static final String CMD_VERSION = "version";
	public static String sendHello(String sVersion, String sControllerName)
	{
		return _bounding(CMD_VERSION, "hello", "version="+sVersion+",name="+sControllerName);
	}
	public static String sendAskVersion()
	{
		return _bounding(CMD_VERSION, "", "");
	}

	/////////////////////////////////
	// Setting
	static final String CMD_SETTING = "setting";
	public static String sendAskSetting()
	{
		return _bounding(CMD_SETTING, "ask", "all");
	}
	public static String sendAskSettingCameraBroadcast()
	{
		return _bounding(CMD_SETTING, "ask", "camera_bc");
	}

	/////////////////////////////////
	// Status
	static final String CMD_STATUS = "status";
	public static String sendAskStatus()
	{
		return _bounding(CMD_STATUS, "ask", "all");
	}

	/////////////////////////////////
	// Reset
	static final String CMD_RESET = "reset";
	public static String sendReset()
	{
		return _bounding(CMD_RESET, "", "");
	}

	/////////////////////////////////
	// Servo
	static final String CMD_SERVO = "s";
	public static String sendAskAllServoPositions()
	{
		return _bounding(CMD_SERVO, "ask", "all");
	}

	/////////////////////////////////
	// Message
	static final String CMD_NOTIFICATION = "notification";
	public static String sendMessage(String sMsg)
	{
		return _bounding(CMD_NOTIFICATION, "message", sMsg);
	}
	public static String sendVibration(String sVib)
	{
		return _bounding(CMD_NOTIFICATION, "vibrate", sVib);
	}
}
